<template>
  <el-container>
    <el-header>
      <img :src="url" alt="" />
      <h3>科泰管理系统</h3>

      <el-dropdown trigger="click" @command="handleCommand">
        <img :src="url" alt="" />
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item icon="el-icon-house" command="a"
            >首页</el-dropdown-item
          >
          <el-dropdown-item icon="el-icon-switch-button" command="b"
            >退出</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :router="true"
        >
          <MenuTree :menuList="menuList"></MenuTree>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapMutations } from 'vuex'; 
import { USERLOGIN,USERLOGOUT } from '@/store/types';
import { getMenuList } from "@/api/menu.js";
import MenuTree from "../../components/MenuTree.vue";
export default {
  data() {
    return {
      url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fdingyue.ws.126.net%2F2021%2F0627%2F3885b7feg00qvd3r6004dd200hs00hsg00hs00hs.gif&refer=http%3A%2F%2Fdingyue.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1663917722&t=94fba272d5dff273f3dbd28707969e15",
      menuList: [],
      openIds: [],
    };
  },
  methods: {
    ...mapMutations([USERLOGIN,USERLOGOUT]),
    handleCommand(command) {
      if (command === "b") {
        this[USERLOGOUT]();
        this.$router.push("/login");
      }
    },
    async getMenus() {
      let result = await getMenuList();
      this.menuList = result.data.menuTree;
      this.openIds = result.data.ids;
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
  created() {
    this.getMenus();
  },
  components: {
    MenuTree,
  },
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}

.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px 20px;
  img {
    border: 1px solid #dcdfe6;
    border-radius: 50%;
    width: 60px;
    height: 60px;
  }
}

.el-aside {
  background-color: #545c64;
}

.el-main {
  background-color: #e9eef3;
}

.el-menu {
  border: 0;
}
</style>